import 'package:flutter/material.dart';

import "entity/list_item.dart";

final items = List<ListItem>.generate(
  20,
  (index) {
    if (index % 2 == 0) {
      return HeadingItem(heading: "heading $index");
    } else {
      return MessageItem(sender: "sender $index", body: "body $index");
    }
  }
);

class ListViewWithVariousItem extends StatelessWidget {
  const ListViewWithVariousItem({ super.key });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("ListView with Various Item")),
      body: ListView.builder(
        itemCount: 20,
        itemBuilder: (context, index) {
          final item = items[index];
          return ListTile(
            title: item.buildTitle(context),
            subtitle: item.buildSubtitle(context),
          );
        }
      )
    );
  }
}